﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HotelManagement.Class;

namespace HotelManagement.UserManagementModule
{
    public partial class UpdateMe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                UserAccount us = (UserAccount)Session["object"];
                Label3.Text = us.FirstName + " " + us.LastName; //heading
                Staff s = (Staff)Session["detail"];
                Label4.Text = s.StaffID;
                Label5.Text = us.UserID; //username
                Label6.Text = us.Role; //role
                TextBox1.Text = s.FirstName;
                TextBox2.Text = s.LastName;
                Label9.Text = s.Gender;
                Label10.Text = s.DateOfBirth;
                TextBox10.Text = Convert.ToString(s.MobileNum);
                TextBox11.Text = Convert.ToString(s.HomeNum);
                TextBox5.Text = s.EmailAddress;
                TextBox6.Text = s.BlockNum;
                TextBox7.Text = s.UnitNum;
                TextBox8.Text = s.StreetName;
                Label11.Text = s.Country;
                TextBox9.Text = s.PostalCode;
            }
        }

        protected void Button1_Click(object sender, EventArgs e) //Update button
        {
            Staff stf = new Staff();
            stf.FirstName = TextBox1.Text; //new FirstName
            stf.LastName = TextBox2.Text; //new LastName
            stf.MobileNum = Convert.ToInt32(TextBox10.Text); //new MobileNum
            stf.HomeNum = Convert.ToInt32(TextBox11.Text); //new HomeNum
            stf.EmailAddress = TextBox5.Text; //new Email
            stf.BlockNum = TextBox6.Text; //new Blk
            stf.UnitNum = TextBox7.Text; //new UnitNum
            stf.StreetName = TextBox8.Text; //new StreetName
            stf.PostalCode = TextBox9.Text; //new postalcode

            if (HotelDBManager.updateStaffInfoByID(Convert.ToInt32(((Staff)Session["detail"]).StaffID), stf) == 1) //update the data in Staff and UserAccount table
            {
                Session["updated"] = stf; //new updated data
                Response.Redirect("~/UserManagementModule/UpdateSuccess.aspx");
            }
            else
                Label12.Visible = true; //update fail
        }
    }
}